package cp3120.dao.remote;

import cp3120.dao.FlightDAO;
import cp3120.model.Airport;
import cp3120.model.FlightSearch;
import generic.net.client.Client;
import cp3120.model.Flight;
import java.util.List;

/**
 *
 * @author Adam Scarr <scarr.adam@gmail.com>
 */
public class RemoteFlightDAO implements FlightDAO {
    private Client client;
    /**
     * Identifies this service
     */
    private static final String service = "RemoteFlightService";

    /**
     * creates a RemoteFlightDAO and sets the client
     * @param client the client this DAO is connected too
     */
    public RemoteFlightDAO(Client client) {
        this.client = client;
    }

    /**
     * sends a request to the server for a flight
     * @param flightID the flight to be retrieved
     * @return the flight sent from the server
     */
    public Flight getFlight(int flightID) {
        return (Flight)client.sendRequest(service, "getFlight", flightID).getResponse().getPayload();
    }

    /**
     * sends a request to the server for a list of all flights
     * @return a list of flights sent from the server
     */
    public List<Flight> getFlights() {
        return (List<Flight>)client.sendRequest(service, "getFlights").getResponse().getPayload();
    }

    /**
     * sends a request to the server to update a flight
     * @param flight the updated flight
     * @return a boolean result from the server
     */
    public boolean updateFlight(Flight flight) {
        return (Boolean)client.sendRequest(service, "updateFlight", flight).getResponse().getPayload();
    }

    /**
     * sends a request to the server to add a flight
     * @param flight the flight to be added
     * @return a boolean result from the server
     */
    public boolean addFlight(Flight flight) {
        return (Boolean)client.sendRequest(service, "addFlight", flight).getResponse().getPayload();
    }

    /**
     * sends a request to the server to delete a flight
     * @param flight the flight to be deleted
     * @return a boolean result from the server
     */
    public boolean deleteFlight(Flight flight) {
        return (Boolean)client.sendRequest(service, "deleteFlight", flight).getResponse().getPayload();
    }

    /**
     * sends a request to the server to get an airport
     * @param airportID the Id of the airport to be retrieved
     * @return an airport object from the server
     */
    public Airport getAirport(int airportID) {
        return (Airport)client.sendRequest(service, "getAirport", airportID).getResponse().getPayload();
    }

    /**
     * sends a request to the server for a list of all ariports
     * @return a list airports fromt he server
     */
    public List<Airport> getAirports() {
        return (List<Airport>)client.sendRequest(service, "getAirports").getResponse().getPayload();
    }

    /**
     * sends a request to the server to update an airport
     * @param airport the updated airport
     * @return a boolean result from the server
     */
    public boolean updateAirport(Airport airport) {
        return (Boolean)client.sendRequest(service, "updateAirport", airport).getResponse().getPayload();
    }

    /**
     * sends a request to the server to add an airport
     * @param airport the new airport to be added
     * @return a boolean result from the server
     */
    public boolean addAirport(Airport airport) {
        return (Boolean)client.sendRequest(service, "addAirport", airport).getResponse().getPayload();
    }

    /**
     * sends a request to the server to delete an airport
     * @param airport the airport to be deleted
     * @return a boolean result from the server
     */
    public boolean deleteAirport(Airport airport) {
        return (Boolean)client.sendRequest(service, "deleteAirport", airport).getResponse().getPayload();
    }

    /**
     * sends a request to the server to get search for flights and return a lsit of search results
     * @param search the search parramaters to be used when searching
     * @return a list of flights from the server matching the search parramaters
     */
    public List<Flight> searchFlights(FlightSearch search) {
        return (List<Flight>)client.sendRequest(service, "searchFlights", search).getResponse().getPayload();
    }
}
